package com.itheima.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class JdbcDemo_Statement {
    public static void main(String[] args) throws Exception {

        //注册驱动  5.5版本后可以省略
        Class.forName("com.mysql.jdbc.Driver");

        //获取连接
        String url = "jdbc:mysql://47.100.230.149:3306/myheima";
        String username = "myheima";
        String password = "myheima";

        Connection conn = DriverManager.getConnection(url, username, password);

        //定义sql
        String sql = "INSERT INTO account (id,name,money) VALUES (3,'王五',3000)";

        //获取sql执行对象
        Statement statement = conn.createStatement();

        //执行sql
        int affNum = statement.executeUpdate(sql);

        //处理结果
        if(affNum > 0){
            System.out.println("执行成功");
        }else {
            System.out.println("执行失败");
        }

        //释放资源
        statement.close();
        conn.close();
    }
}
